<template>
  <div class="stat-card" :class="{ 'hoverable': hoverable }" @click="handleClick">
    <div class="stat-icon" :style="iconStyle">
      <i :class="icon"></i>
    </div>
    <div class="stat-content">
      <div class="stat-title">{{ title }}</div>
      <div class="stat-value">{{ value }}</div>
      <div class="stat-subtitle" v-if="subtitle">{{ subtitle }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StatCard',
  props: {
    title: {
      type: String,
      required: true
    },
    value: {
      type: [String, Number],
      required: true
    },
    subtitle: {
      type: String,
      default: ''
    },
    icon: {
      type: String,
      default: 'el-icon-data-line'
    },
    color: {
      type: String,
      default: '#409EFF'
    },
    hoverable: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    iconStyle() {
      return {
        backgroundColor: this.color
      };
    }
  },
  methods: {
    handleClick() {
      if (this.hoverable) {
        this.$emit('click');
      }
    }
  }
};
</script>

<style scoped>
.stat-card {
  display: flex;
  padding: 16px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  margin-bottom: 16px;
  transition: transform 0.3s, box-shadow 0.3s;
}

.stat-card.hoverable {
  cursor: pointer;
}

.stat-card.hoverable:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  margin-right: 16px;
  color: white;
  font-size: 24px;
}

.stat-content {
  flex: 1;
}

.stat-title {
  font-size: 14px;
  color: #606266;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 4px;
}

.stat-subtitle {
  font-size: 12px;
  color: #909399;
}
</style> 